<template>
	<div :id="id" :class="ns.b()" :style="{ zIndex: zIndex }" @click.self="onClose">
		<div :class="ns.e('container')" :style="{ width }">
			<div :class="ns.b('header')">
				<span :class="ns.be('header', 'title')">{{ title }}</span>
				<span :class="ns.be('header', 'close')" @click="onClose">
					<el-icon size="24">
						<Close />
					</el-icon>
				</span>
			</div>
			<div :class="ns.b('content')">
				<slot name="content"></slot>
			</div>
			<div :class="ns.b('bottom')">
				<slot name="bottom"></slot>
			</div>
		</div>
	</div>
</template>

<script lang="ts" setup>
import { useNamespace } from "@/hooks";
import { PopupEvent } from "../type";
import { Close } from "@element-plus/icons-vue";
import { DialogPropOptions } from "./type";
const ns = useNamespace("dialog");

const props = withDefaults(
	defineProps<DialogPropOptions & { zIndex: number; id: string } & Omit<PopupEvent, 'repaint'>>(),
	{
		width: "",
	}
);
const onClose = () => {
	props?.shutDown();
};
</script>

<style lang="scss" scoped>
$ns: dialog;
$dialog-space: 20px;

@include block($ns) {
	position: fixed;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	background-color: rgba(0, 0, 0, 0.3);
	backdrop-filter: blur(1px);
	overflow: auto;

	@include element(container) {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		min-width: 20%;

		background-color: var(--bg-color-light1);
		border-radius: 3px;
		display: flex;
		flex-direction: column;
	}
}

@include block(#{$ns}-content) {
	width: 100%;
	flex: 1;
	padding: $dialog-space;
	box-sizing: border-box;
}

@include block(#{$ns}-bottom) {
	width: 100%;
	padding: 0 $dialog-space;
	box-sizing: border-box;
}

@include block(#{$ns}-header) {
	width: 100%;
	padding: 10px $dialog-space;

	border-bottom: 0.5px solid var(--bg-color-light6);
	box-sizing: border-box;
	position: relative;
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-radius: 3px;

	@include element(title) {
		display: flex;
		align-items: baseline;
		height: 21px;
		line-height: 20px;
		font-weight: bold;
	}

	@include element(close) {
		width: 21px;
		height: 21px;
		line-height: 21px;
		font-weight: normal;
		cursor: pointer;
		color: var(--text-color-regular);

		&:hover {
			color: var(--intent-color-theme);
		}
	}
}
</style>
